<template>
    <div class="home-tool-bar ">
      <a href="" class="item1 item-image" >
        <div class="icon">
          <img src="../assets/imgs/right-icon.png" alt="" class="static">
          <img src="../assets/imgs/right-icon1.png" alt="" class="hover">
        </div>
        <span class="text">手机APP</span>
        <div class="pop-content">
          <img src="../assets/imgs/wx-img.png" alt="">
          <span class="desc">扫码领取新人百元礼包</span>
        </div>
      </a>
      <a href="" class="item1 item-image" v-for="i in 4" :key="i">
        <div class="icon">
          <img src="../assets/imgs/right-icon.png" alt="" class="static">
          <img src="../assets/imgs/right-icon1.png" alt="" class="hover">
        </div>
        <span class="text">手机APP</span>
      </a>
      <a href="" class="item1 backtop" @click="returnTop">
        <div class="icon">
          <img src="../assets/imgs/right-icon.png" alt="" class="static" >
          <img src="../assets/imgs/right-icon1.png" alt="" class="hover">
        </div>
        <span class="text">返回顶部</span>
      </a>
    </div>
</template>

<script>
export default {
  data(){
    return{
      isShow : false
    }
  },
  created(){
    const html = document.documentElement;
    document.addEventListener('scroll', (e) => {
      let scrolled = html.scrollTop / (html.scrollHeight - html.clientHeight)
      let scrollTop = document.querySelector('.backtop')

      if(scrolled>0.3){
        scrollTop.style.visibility = 'visible'
      }else{
        scrollTop.style.visibility = 'hidden'
      }
    })
  },
  methods:{
    returnTop(){
      document.body.scrollTop = 0;
      document.documentElement.scrollTop = 0;
    }
  }
}
</script>

<style lang="less" scoped>
.home-tool-bar{
  position: fixed;
  bottom: 70px;
  right: 0;
  z-index: 99;
  .item1{
    position: relative;
    display: block;
    width: 82px;
    height: 90px;
    margin-top: -1px;
    background-color: #fff;
    border: 1px solid #f5f5f5;
    text-align: center;
    .icon{
      position: relative;
      width: 30px;
      height: 30px;
      margin: 0 auto 8px;
      padding-top: 18px;
      img{
        position: absolute;
        bottom: 0;
        left: 0;
        width: 30px;
        height: 30px;
        -webkit-transition: opacity .3s;
        transition: opacity .3s;
      }
      .static{
        opacity: 1;
      }
      .hover{
        opacity: 0;
      }
    }
    .text{
      color: #757575;
      -webkit-transition: color .3s;
      transition: color .3s;
    }
    .pop-content{
      position: absolute;
      left: 0;
      top: 0;
      padding: 14px;
      background: #fff;
      border: 1px solid #f5f5f5;
      -webkit-transition: opacity .3s;
      transition: opacity .3s;
      -webkit-transform: translateZ(0);
      transform: translateZ(0);
      opacity: 0;
      visibility: hidden;
      img{
        display: block;
        width: 100px;
        height: 100px;
        margin: 6px auto;
      }
      .desc{
        display: block;
        width: 82px;
        margin: 14px auto 0;
        color: #757575;
        text-align: center;
      }
    }
    .pop-content::before{
      content: "";
      position: absolute;
      top: 21%;
      width: 0;
      height: 0;
      border-width: 10px;
      border-style: solid;
      overflow: hidden;
      right: -19px;
      border-color: rgba(0,0,0,0) rgba(0,0,0,0) rgba(0,0,0,0) #f5f5f5;
      z-index: 1;
    }
    .pop-content::after{
      content: "";
      position: absolute;
      top: 21%;
      width: 0;
      height: 0;
      border-width: 10px;
      border-style: solid;
      overflow: hidden;
      right: -18px;
      border-color: rgba(0,0,0,0) rgba(0,0,0,0) rgba(0,0,0,0) #fff;
      z-index: 2;
    }
  }
  .item1:hover .text{
    color: #ff6700;
  }
  .item1:hover .static{
    opacity: 0;
  }
  .item1:hover .hover{
    opacity: 1;
  }
  .item-image:hover .pop-content{
    visibility: visible;
    opacity: 1;

    transform: translate3d(-110%,0,0);
  }
    
}
.backtop{
  margin-top: 14px !important;
  border-top: 1px solid #f5f5f5 !important;
  visibility: hidden;
}
</style>